﻿/*   
    Copyright (C) 2009 Galaktika Corporation ZAO

    This file is a part of Galaktika.BusinessMonitor
 
    Galaktika.BusinessMonitor is a free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
      
    You should have received a copy of the GNU General Public License
    along with Galaktika.BusinessMonitor.  If not, see <http://www.gnu.org/licenses/>.
  
    If GPL v.3 is not suitable for your products or company,
    Galaktika Corp provides Galaktika.BusinessMonitor under a flexible commercial license
    designed to meet your specific usage and distribution requirements.
    If you have already obtained a commercial license from Galaktika Corp,
    you can use this file under those license terms.
*/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.Collections.Generic;
using System.Windows.Browser;
using System.Resources;

namespace Galaktika.BI.Silverlight.Controls
{
    public static class UriResources
    {
        private static Dictionary<string, BitmapImage> m_Cashe = null;
        public static Dictionary<string, BitmapImage> Cashe
        {
            get{
                if (m_Cashe == null)
                    m_Cashe = new Dictionary<string, BitmapImage>();
                return m_Cashe;
            }
        } 

        public static string GetResourceString(string assemblyName, string resourcePath)
        {
            string[] parts = resourcePath.Split('.');
            string resultPath = string.Empty;
            foreach (var s in parts)
            {
                if ( s.ToLower().Equals("image") || s.ToLower().Equals("indicators") || s.ToLower().Equals("x16") )
                    resultPath += s + "/";
                else
                    resultPath += s + ".";                    
            }
            return String.Format("/{0};component/{1}", assemblyName, resultPath.Remove(resultPath.Length - 1));
        }


        public static BitmapImage GetImage(string resourceUri)
        {
            if (Cashe.ContainsKey(resourceUri))
            {
                return Cashe[resourceUri];
            }
            else
            {
                BitmapImage bmp = new BitmapImage(new Uri(resourceUri, UriKind.Relative));
               if (bmp != null)
               {
                   Cashe.Add(resourceUri, bmp);
               }
               return bmp;
            }
        }

        public static BitmapImage GetImage(string assemblyName, string resourcePath)
        {
            return GetImage(GetResourceString(assemblyName, resourcePath.Remove(0, assemblyName.Length + 1)));
        }

        public class Images
        {
            #region PivotGrid
            const string ACTION_NODE_16 = "/Galaktika.BI.Silverlight;component/Controls/PivotGrid/Images/ActionNode.png";

            public static BitmapImage ActionNode16
            {
                get
                {
                    return UriResources.GetImage(ACTION_NODE_16);
                }
            }

            #endregion PivotGrid

            #region Other

            const string CHECKED_BUTTON_16 = "/Galaktika.BI.Silverlight;component/Controls/PivotGrid/Images/Plus.png";

            public static BitmapImage CheckedButton16
            {
                get
                {
                    return UriResources.GetImage(CHECKED_BUTTON_16);
                }
            }

            const string UNCHECKED_BUTTON_16 = "/Galaktika.BI.Silverlight;component/Controls/PivotGrid/Images/Minus.png";

            public static BitmapImage UnCheckedButton16
            {
                get
                {
                    return UriResources.GetImage(UNCHECKED_BUTTON_16);
                }
            }
            #endregion
        }
    }
}
